<?php


namespace app\common\lists;

trait ListsSortTrait
{

    protected $orderBy;
    protected $sort;

    /**
     * @param $sortField
     * @param $defaultOrder
     * @return array
     */
    private function createSort($sortFields, $order, $sort)
    {
        if (!$sortFields) {
            $this->orderBy = $order;
            $this->sort = $sort;
            return;
        }
        foreach ($sortFields as $key => $sortField) {
            if ($key === $order) {
                $this->orderBy = $sortField;
                $this->sort = $sort;
                return;
            } else {
                continue;
            }
        }
        $this->orderBy = $order;
        $this->sort = $sort;
        return;
    }
}